/*
 *  WMaterial.cpp
 *  GLRender
 *
 *  Created by Patrick zulian on 5/23/10.
 *  Copyright 2010 University  of Lugano. All rights reserved.
 *
 */

#include "WMaterial.h"
#include <QtOpenGL>

WMaterial::WMaterial(const RGBd &diffuse, int target)
: emmission(0.0, 0.0, 0.0), ambient(0.2, 0.2, 0.2), diffuse(diffuse), specular(0.5, 0.5, 0.5), shininess(1.0), target(target)
{
	
	
}
void
WMaterial::set()
{
	
	glEnable( GL_LIGHTING );
	GLfloat mat_emission[] = { emmission.r(), emmission.g(), emmission.b(), 0.0 }; 
	GLfloat mat_ambient [] = { ambient.r(), ambient.r(), ambient.r(), 1.0 };
	GLfloat mat_diffuse [] = { diffuse.r(), diffuse.g(), diffuse.b(), 1.0 };
	GLfloat mat_specular[] = { specular.r(), specular.g(), specular.b(), 1.0 };
	
	glMaterialfv( target, GL_EMISSION, mat_emission );
	glMaterialfv( target, GL_AMBIENT,  mat_ambient  );
	glMaterialfv( target, GL_DIFFUSE,  mat_diffuse  );
	glMaterialfv( target, GL_SPECULAR, mat_specular );
	glMaterialf ( target, GL_SHININESS, shininess );

}

void
WMaterial::setForLight()
{
	setForLight(target);
}


void
WMaterial::setForLight(int target)
{
 
	GLfloat mat_ambient [] = { ambient.r(), ambient.r(), ambient.r(), 1.0 };
	GLfloat mat_diffuse [] = { diffuse.r(), diffuse.g(), diffuse.b(), 1.0 };
	GLfloat mat_specular[] = { specular.r(), specular.g(), specular.b(), 1.0 };
	
	glLightfv( target, GL_AMBIENT,  mat_ambient  );
	glLightfv( target, GL_DIFFUSE,  mat_diffuse  );
	glLightfv( target, GL_SPECULAR, mat_specular );
	
	
}

